package cn.iocoder.yudao.module.call.controller.admin.aiqualitytestingelsecondition;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.call.controller.admin.aiqualitytestingelsecondition.vo.*;
import cn.iocoder.yudao.module.call.dal.dataobject.aiqualitytestingelsecondition.AiQualityTestingElseConditionDO;
import cn.iocoder.yudao.module.call.service.aiqualitytestingelsecondition.AiQualityTestingElseConditionService;

@Tag(name = "管理后台 - 大模型质检其他条件")
@RestController
@RequestMapping("/call/ai-quality-testing-else-condition")
@Validated
public class AiQualityTestingElseConditionController {

    @Resource
    private AiQualityTestingElseConditionService aiQualityTestingElseConditionService;

    @PostMapping("/create")
    @Operation(summary = "创建大模型质检其他条件")
    @PreAuthorize("@ss.hasPermission('call:ai-quality-testing-else-condition:create')")
    public CommonResult<Long> createAiQualityTestingElseCondition(@Valid @RequestBody AiQualityTestingElseConditionSaveReqVO createReqVO) {
        return success(aiQualityTestingElseConditionService.createAiQualityTestingElseCondition(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新大模型质检其他条件")
    @PreAuthorize("@ss.hasPermission('call:ai-quality-testing-else-condition:update')")
    public CommonResult<Boolean> updateAiQualityTestingElseCondition(@Valid @RequestBody AiQualityTestingElseConditionSaveReqVO updateReqVO) {
        aiQualityTestingElseConditionService.updateAiQualityTestingElseCondition(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除大模型质检其他条件")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('call:ai-quality-testing-else-condition:delete')")
    public CommonResult<Boolean> deleteAiQualityTestingElseCondition(@RequestParam("id") Long id) {
        aiQualityTestingElseConditionService.deleteAiQualityTestingElseCondition(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得大模型质检其他条件")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('call:ai-quality-testing-else-condition:query')")
    public CommonResult<AiQualityTestingElseConditionRespVO> getAiQualityTestingElseCondition(@RequestParam("id") Long id) {
        AiQualityTestingElseConditionDO aiQualityTestingElseCondition = aiQualityTestingElseConditionService.getAiQualityTestingElseCondition(id);
        return success(BeanUtils.toBean(aiQualityTestingElseCondition, AiQualityTestingElseConditionRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得大模型质检其他条件分页")
    @PreAuthorize("@ss.hasPermission('call:ai-quality-testing-else-condition:query')")
    public CommonResult<PageResult<AiQualityTestingElseConditionRespVO>> getAiQualityTestingElseConditionPage(@Valid AiQualityTestingElseConditionPageReqVO pageReqVO) {
        PageResult<AiQualityTestingElseConditionDO> pageResult = aiQualityTestingElseConditionService.getAiQualityTestingElseConditionPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AiQualityTestingElseConditionRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出大模型质检其他条件 Excel")
    @PreAuthorize("@ss.hasPermission('call:ai-quality-testing-else-condition:export')")
    @OperateLog(type = EXPORT)
    public void exportAiQualityTestingElseConditionExcel(@Valid AiQualityTestingElseConditionPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<AiQualityTestingElseConditionDO> list = aiQualityTestingElseConditionService.getAiQualityTestingElseConditionPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "大模型质检其他条件.xls", "数据", AiQualityTestingElseConditionRespVO.class,
                        BeanUtils.toBean(list, AiQualityTestingElseConditionRespVO.class));
    }

}